<?php
class OliyoServer
{
	/**
	 * Get Forecast info by date
	 * @param datetime $date
	 * @return mixed
	 */
	public static function  getTodayAstor($date=''){
		$_cache_id = Yii::app()->params['SITE_CACHE_ID']['TODAY_ASTOR_CACHE'];
		$data = Yii::app()->cache->get($_cache_id['id']);
		if(empty($data))
		{
			$data = array();
			$today = strtotime(date("Ymd",time())-1);
			if($date!=''){
				$today=strtotime($date);
			}
			$criteria=new CDbCriteria;
			$criteria->select = array('astor_name','astor_mark');
			$criteria->condition='info_date=:info_date';
			$criteria->params=array(':info_date'=>(int)$today);
			$astors = AstorMaster::model()->with('forecast','infoProtype')->findAll($criteria);
			if(!empty($astors)){
				$data['statu_code'] = 200;
				$data['count'] = count($astors);
				$data['date'] = date('Y-m-d',$today);
				$p = 0;
				foreach($astors as $ast){
					$p++;
					$data['data'][] = array(
							'astor'			=>	$ast->astor_mark,
							'name'			=>	$ast->astor_name,
							'supei'			=>	Yii::app()->params["astor_name_id"][$ast->forecast[0]->supei][0],
							'zonghe'		=>	$ast->forecast[0]->zonghe,
							'aiqing'		=>	$ast->forecast[0]->aiqing,
							'gongzuo'		=>	$ast->forecast[0]->gongzuo,
							'lucky_color'	=>	$ast->forecast[0]->lucky_color,
							'lucky_num'		=>	$ast->forecast[0]->lucky_num,
							'analysis'		=>	$ast->forecast[0]->analysisContent,							
					);
				}

			}
			Yii::app()->cache->set($_cache_id['id'],$data,$_cache_id['time']);
		}
		return  $data;
	}
}